import request from '@/utils/request'

// 获取拼团列表
export function fetchGroupList(query) {
  return request({
    url: 'shopgroup/list',
    method: 'get',
    params: query
  })
}

// 创建拼团
export function createGroup(data) {
  return request({
    url: 'shopgroup/save',
    method: 'post',
    data
  })
}

// 更新拼团
export function updateGroup(data) {
  return request({
    url: 'shopgroup/save',
    method: 'post',
    data
  })
}

// 删除拼团
export function deleteGroup(id) {
  return request({
    url: `shopgroup/delete`,
    method: 'post',
    data: {
      id
    }
  })
}

// 修改拼团状态
export function updateGroupStatus(id, status) {
  return request({
    url: `shopgroup/status/${id}`,
    method: 'put',
    data: { status }
  })
}

// 秒杀管理相关API
// 获取秒杀列表
export function fetchMiaoshaList(query) {
  return request({
    url: 'seckill/list',
    method: 'get',
    params: query
  })
}

// 创建秒杀活动
export function createMiaosha(data) {
  return request({
    url: 'seckill/save',
    method: 'post',
    data
  })
}

// 更新秒杀活动
export function updateMiaosha(data) {
  return request({
    url: 'seckill/save',
    method: 'post',
    data
  })
}

// 删除秒杀活动
export function deleteMiaosha(id) {
  return request({
    url: `seckill/delete`,
    method: 'post',
    data: {
      id
    }
  })
}

// 修改秒杀状态
export function updateMiaoshaStatus(id, status) {
  return request({
    url: `seckill/status/${id}`,
    method: 'put',
    data: { status }
  })
}

// 优惠券管理相关API
// 获取优惠券列表
export function fetchCouponList(query) {
  return request({
    url: 'shopcoupon/list',
    method: 'get',
    params: query
  })
}

// 创建优惠券
export function createCoupon(data) {
  return request({
    url: 'shopcoupon/save',
    method: 'post',
    data
  })
}

// 更新优惠券
export function updateCoupon(data) {
  return request({
    url: 'shopcoupon/save',
    method: 'post',
    data
  })
}

// 删除优惠券
export function deleteCoupon(id) {
  return request({
    url: 'shopcoupon/delete',
    method: 'post',
    data: {
      id
    }
  })
}

// 修改优惠券状态
export function updateCouponStatus(id, status) {
  return request({
    url: 'shopcoupon/status',
    method: 'post',
    data: { id, status }
  })
}

// 赠送优惠券
export function giftCoupon(data) {
  return request({
    url: 'shopcoupon/gift_coupon',
    method: 'post',
    data
  })
}

// 获取优惠券领取记录列表
export function fetchCouponRecordList(query) {
  return request({
    url: 'shopcoupon/record',
    method: 'post',
    data: query
  })
}

export function fetchList(query) {
  return request({
    url: 'shopgroup/intentionList',
    method: 'get',
    params: query
  })
}

